package com.sfac.javaSpringBoot.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.javaSpringBoot.modules.account.entity.Role;
import com.sfac.javaSpringBoot.modules.account.service.RoleService;
import com.sfac.javaSpringBoot.modules.common.entity.Result;
import com.sfac.javaSpringBoot.modules.common.entity.SearchBean;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /*
    * 127.0.0.1/api/role   post
    * {"roleName":"xiaoming"}
    *
    * */
    @PostMapping(value = "/role", consumes = "application/json")
    public Result<Role> insertRole(@RequestBody Role role) {
        return roleService.insertRole(role);
    }

    /*
     * 127.0.0.1/api/role   put
     *
     * */
    @PutMapping(value = "/role", consumes = "application/json")
    public Result<Role> updateRole(@RequestBody Role role) {
        return roleService.updateRoleById(role);
    }

    /*
    * 127.0.0.1/api/role/id  delete
    * */
    @DeleteMapping("/role/{id}")
    public Result<Role> deleteRoleById(@PathVariable int id) {
        return roleService.deleteRoleById(id);
    }

    /*
     * 127.0.0.1/api/role/id  get
     * */
    @GetMapping("/role/{id}")
    public Role queryRoleById(@PathVariable int id) {
        return roleService.queryRoleById(id);
    }

    /*
    * 127.0.0.1/api/roles  get
    * */
    @GetMapping("/roles")
    public List<Role> queryRoleAll() {
        return roleService.queryRoleAll();
    }

    /**
     * 127.0.0.1/api/roles ---- post
     * {"currentPage":"1","pageSize":"5","orderBy":"id","direction":"desc","keyWord":""}
     */
    @PostMapping(value = "/roles", consumes = "application/json")
    public PageInfo<Role> getRolesBySearchBean(@RequestBody SearchBean searchBean) {
        return roleService.getRolesBySearchBean(searchBean);
    }
}
